<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]-->
  <title>天量科技管理后台</title>
  <meta name="keywords" content="" />
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width">
  <link href="favicon.ico" rel="shortcut icon" type="image/x-icon">
  <link rel="stylesheet" href="css/templatemo_main.css">
  <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body ng-app="app" ng-controller="index">
<div class="navbar navbar-inverse" role="navigation">
  <div class="navbar-header">
    <div class="logo"><h1>天量科技管理后台</h1></div>
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
  </div>
</div>
<div class="template-page-wrapper">
  <div class="navbar-collapse collapse templatemo-sidebar">
    <ul class="templatemo-sidebar-menu">
      <li>
        <form class="navbar-form">
          欢迎您:{{user.name || '访客'}}</span>
        </form>
      </li>
      <li ng-repeat="menu in menus" ng-class="menu.menuclass" ng-click="menuclick(menu)">
        <a ng-click="redi(menu.url)" ng-if="menu.items.length==0"><i ng-class="menu.icon"></i>{{menu.label}}</a>
        <a href="#" ng-if="menu.items.length>0">
          <i ng-class="menu.icon"></i> {{menu.label}} <div class="pull-right"><span class="caret"></span></div>
        </a>
        <ul class="templatemo-submenu" ng-if="menu.items.length>0">
          <li ng-repeat="item in menu.items" ng-click="redi(item.url)"><a href="javascript:void(0)">{{item.label}}</a></li>
        </ul>
      </li>
      <li>
        <a href="#" data-toggle="modal" data-target="#confirmModal"><i class="fa fa-sign-out"></i>退出登录</a>
      </li>
    </ul>
  </div><!--/.navbar-collapse -->

  <div class="templatemo-content-wrapper">
    <div class="templatemo-content">
      <ol class="breadcrumb">
        <li><a ng-click="redi('index.html')" href="javascript:void(0)">首页</a></li>
      </ol>

      <div class="row" ng-if="haserror">
        <div class="alert alert-danger alert-dismissible" role="alert">
          <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
          <strong>发生异常情况:{{errormessage}}</strong>
        </div>
      </div>

      <div class="row" ng-repeat="s in systeminfo.list" ng-if="isAdmin">
        <div class="col-md-6 margin-bottom-15">
          <div class="panel panel-primary">
            <div class="panel-heading">{{s.name}}</div>
            <div class="panel-body">
              <table class="table table-striped table-hover table-bordered">
                <tr>
                  <th>名称</th>
                  <th>值</th>
                </tr>
                <tr>
                  <td>服务器地址</td>
                  <td>{{s.server_ip}}</td>
                </tr>
                <tr>
                  <td>服务器主机名</td>
                  <td>{{s.server_hostname}}</td>
                </tr>
                <tr>
                  <td>操作系统名</td>
                  <td>{{s.os_name}}</td>
                </tr>
                <tr>
                  <td>JVM版本</td>
                  <td>{{s.jvm_version}}</td>
                </tr>
                <tr>
                  <td>启动时间</td>
                  <td>{{s.startTime  | date: 'yyyy-MM-dd hh:mm:ss'}}</td>
                </tr>
                <tr>
                  <td>更新时间</td>
                  <td>{{s.updatedTime  | date: 'yyyy-MM-dd hh:mm:ss'}}</td>
                </tr>
                <tr>
                  <td>到期时间</td>
                  <td>{{s.expireTime  | date: 'yyyy-MM-dd hh:mm:ss'}}</td>
                </tr>
              </table>
            </div>
          </div>
        </div>

        <div class="col-md-3 margin-bottom-15">
          <div class="row templatemo-chart-row">
            <div class="templatemo-chart-box col-lg-12 col-md-12 col-sm-12 col-xs-12">
              <div id="chart_os_{{s.name}}" style="width:{{wWidth*0.2}}px;height:{{wHeigth*0.3}}px;"></div>
            </div>
          </div>
        </div>
        <div class="col-md-3 margin-bottom-15">
          <div class="row templatemo-chart-row">
            <div class="templatemo-chart-box col-lg-12 col-md-12 col-sm-12 col-xs-12">
              <div id="chart_jvm_{{s.name}}" style="width:{{wWidth*0.2}}px;height:{{wHeigth*0.3}}px;"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <!-- Modal -->
  <div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
          <h4 class="modal-title" id="myModalLabel">确定退出吗</h4>
        </div>
        <div class="modal-footer">
          <a ng-click="logout()" class="btn btn-primary" data-dismiss="modal">确定</a>
          <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        </div>
      </div>
    </div>
  </div>

  <footer class="templatemo-footer">
    <div class="templatemo-copyright">
      <p>Copyright &copy; 2018 By <a href="http://skyquant.cn" title="天量科技" target="_blank">天量科技</a></p>
    </div>
  </footer>
</div>
</body>

<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<script src="//cdn.bootcss.com/angular.js/1.5.8/angular.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="js/common.js"></script>
<script src="js/templatemo_script.js"></script>
<script src="https://cdn.bootcss.com/echarts/4.1.0-release/echarts.min.js"></script>
<script type="text/javascript">
  'use strict';
  var app = angular.module('app', []);
  app.controller('index', ['$scope', '$http','$location', '$filter','$window','$timeout',function ($scope, $http,$location,$filter,$window,$timeout) {

      //每个页面都要有的方法begin
      $scope.init = function(){
        $scope.wHeigth=$window.innerHeight;//获取屏幕的高度
        $scope.wWidth=$window.innerWidth;//获取屏幕的宽度
        getUser($http,$scope,'系统信息','系统信息');
      }

      $scope.logout = function(){
        logout($http);
      }

      $scope.menuclick=function(menu){
        changemenuclass($scope,menu);
      }

      $scope.redi=function(url){
          location.href = url;
      }
      //每个页面都要有的方法begin

      //每个页面都需要重写此方法，发生在init之后
      $scope.initAfter = function(){
        $scope.isAdmin = $scope.user.roles.contain('administrator');
        $scope.initSystenInfo();
      }

      $scope.init();

      $scope.initSystenInfo = function(){
        $http({method:'GET',url:'quant4j-service/system/info'}).success(function(data,header,config,status) {
          if(data.ok){
            $scope.systeminfo = data.data;
            $http({method:'GET',url:'quant4j-service/system/info'}).success(function(data,header,config,status) {
              $scope.initchart(data.data);
            });
          }else{
            $scope.haserror = true;
            $scope.errormessage = data.message;
          }
        }).error(function(data,header,config,status){
            $scope.haserror = true;
            $scope.errormessage = data.message;
        });
      }


      $scope.initchart = function(data){
        data.list.forEach(function(v,index){
          var os_chartdiv = document.getElementById('chart_os_'+v.name);
          var os_myChart = echarts.init(os_chartdiv);
          var os_option = {
              title : {
                  text: 'OS内存',
                  x:'center'
              },
              legend: {
                  type: 'scroll',
                  orient: 'vertical',
                  right: 10,
                  top: 20,
                  bottom: 20,
                  data: ['已用','可用'],
                  selected: data.selected
              },
              tooltip : {
                  trigger: 'item',
                  axisPointer: {
                      type: 'cross'
                  },
                  formatter: function(params) {
                     return params.name+':'+Math.round(params.value/(1024*1024))+'MB<br>占比:'+params.percent+'%';
                  }
              },
              series: [{
                  data: [{name: '已用',value: v.os_max-v.os_free}, {name: '可用',value:v.os_free}],
                  type: 'pie',
                  radius : '55%',
                  center: ['40%', '50%'],
                  itemStyle: {
                      emphasis: {
                          shadowBlur: 10,
                          shadowOffsetX: 0,
                          shadowColor: 'rgba(0, 0, 0, 0.5)'
                      }
                  }
              }]
          };
          os_myChart.setOption(os_option);

          var jvm_chartdiv = document.getElementById('chart_jvm_'+v.name);
          var jvm_myChart = echarts.init(jvm_chartdiv);
          var jvm_option = {
              title : {
                  text: 'JVM内存',
                  x:'center'
              },
              legend: {
                  type: 'scroll',
                  orient: 'vertical',
                  right: 10,
                  top: 20,
                  bottom: 20,
                  data: ['已用','可用'],
                  selected: data.selected
              },
              tooltip : {
                  trigger: 'item',
                  axisPointer: {
                      type: 'cross'
                  },
                  formatter: function(params) {
                     return params.name+':'+Math.round(params.value/(1024*1024))+'MB<br>占比:'+params.percent+'%';
                  }
              },
              series: [{
                  data: [{name: '已用',value: v.jvm_total-v.jvm_free}, {name: '可用',value:v.jvm_free}],
                  type: 'pie',
                  radius : '55%',
                  center: ['40%', '50%'],
                  itemStyle: {
                      emphasis: {
                          shadowBlur: 10,
                          shadowOffsetX: 0,
                          shadowColor: 'rgba(0, 0, 0, 0.5)'
                      }
                  }
              }]
          };
          jvm_myChart.setOption(jvm_option);
        });
      }
  }]);
</script>
</html>